import { _decorator, Component, Label, Node } from 'cc';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { AssetList } from '../Global';
import { UIMgr } from '../Mgr/UIMgr';
import { LocalStorageMgr } from '../Mgr/LocalStorageMgr';
const { ccclass, property } = _decorator;

@ccclass('GameRem')
/**
 * 游戏记录
 */
export class GameRem extends Component {

    //最高分数
    @property(Label)
    private labelMaxScore: Label = null;

    //平均分数
    @property(Label)
    private labelAvgScore: Label = null;

    //游戏胜率
    @property(Label)
    private labelWinRate: Label = null;


    public Init() {
        let game_time: number = LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.SUCCESS + LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.FAIL;
        this.labelMaxScore.string = LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.BESTSCORE.toString();

        if (game_time == 0) {
            this.labelAvgScore.string = "0";
            this.labelWinRate.string = "0%";
            return;
        }

        this.labelAvgScore.string = Math.floor(LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.ALLSCORE / game_time).toString();
        this.labelWinRate.string = Math.floor(LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.SUCCESS / game_time * 100).toString() + '%';
    }

    /**
     * 点击关闭按钮
     */
    private CloseClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        UIMgr.Instance.HidePop(AssetList.Pop.GAMEREM);
    }

}


